package by.dvrudenko.avtobaza.webapp.page.car;

import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

import org.apache.wicket.bean.validation.PropertyValidator;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.ResourceModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import by.dvrudenko.avtobaza.datamodel.CarType;
import by.dvrudenko.avtobaza.datamodel.enums.FuelType;
import by.dvrudenko.avtobaza.services.CarTypeService;
import by.dvrudenko.avtobaza.webapp.page.BaseLayout;
import by.dvrudenko.avtobaza.webapp.page.home.HomePage;

public class CarTypeCreatePage extends BaseLayout {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(CarTypeCreatePage.class);

	@Inject
	private CarTypeService carTypeService;
	
	final List<CarType> listCarTypeType = carTypeService.getAllCarType();
	
	public CarTypeCreatePage(final CarType carType) {
		super();
		Form<CarType> formCreateCarType = new Form<CarType>("form", new CompoundPropertyModel<CarType>(carType));
		
		final TextField<String> carTypeBrand = new TextField<String>("brand");
		carTypeBrand.setLabel(new ResourceModel("p.home.car.panel.brand"));	
		carTypeBrand.add(new PropertyValidator<String>());	
		formCreateCarType.add(carTypeBrand);
		
		final TextField<String> carTypeModel = new TextField<String>("model");
		carTypeModel.setLabel(new ResourceModel("p.home.car.panel.model"));	
		carTypeModel.add(new PropertyValidator<String>());	
		formCreateCarType.add(carTypeModel);
		
		final TextField<String> carTypeBody = new TextField<String>("body");
		carTypeBody.setLabel(new ResourceModel("p.home.car.panel.body"));	
		carTypeBody.add(new PropertyValidator<String>());	
		formCreateCarType.add(carTypeBody);
		
		final TextField<String> carTypeCar = new TextField<String>("type");
		carTypeCar.setLabel(new ResourceModel("p.home.car.panel.type"));	
		carTypeCar.add(new PropertyValidator<String>());	
		formCreateCarType.add(carTypeCar);				
		
		
		// сохраняем новый тип машин (CarType)
		formCreateCarType.add(new SubmitLink("sumbit-link") {
			@Override
			public void onSubmit() {
				super.onSubmit();
				LOGGER.info("User create CarType" + user.getLogin());
				carTypeService.saveOrUpdate(carType);

				setResponsePage(HomePage.class);
			}
		});
		
		add(formCreateCarType);
	}



}
